package cn.tedu.v1.mapper;

import cn.tedu.v1.model.Permission;
import cn.tedu.v1.model.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


import java.util.List;

/**
 * <p>
 * 用户列表 Mapper 接口
 * </p>
 *
 * @author tedu.cn
 * @since 2021-07-06
 */

@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("select id,username,password,name,gender,email,phone,id_card,job,married,address,bloodType,info,status,doctor_id from user where username = #{username}")
    User findUserByUsername(String username);

    @Select("select id,username,password,name,gender,email,phone,id_card,job,married,address,bloodType,info,status,doctor_id from user where email = #{email}")
    User findUserByEmail(String email);

    @Select("SELECT p.id,p.name FROM user u LEFT JOIN user_role ur ON u.id=user_id LEFT JOIN role r ON r.id=ur.role_id LEFT JOIN role_pemission rp ON r.id =rp.role_id LEFT JOIN permission p ON p.id=rp.permission_id WHERE u.id=#{id}")
    List<Permission> findUserPermissionsById(Integer id);

    @Select("select id from user where username=#{username}")
    Integer findUserIdByUserName(String username);
}
